home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / igo / gosource / banx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  21.1 KB  |  795 lines

  1. #define DEBUG 0
  2. /* 
  3.   TOWNS囲碁棋譜記録プログラム ban.c
  4.   1992/07/06  久保田俊也
  5.   
  6.   */
  7. #include <stdio.h>
  8. #include <time.h>
  9. #include <string.h>
  10. #include "igo.h"
  11. #include "banx.h"
  12. #include "kiffile.h"
  13. #include "kifuctrl.h"
  14. #include "title.h"
  15.  
  16. static int banx_uchiage2(int ichi);
  17. static int banx_gchk();
  18. static int banx_ginit();
  19. static int banx_do_judge();
  20. static int banx_gset(GCELL *g_ptr, int ichi, char *dameban);
  21. static int banx_gdel(GCELL *g_ptr);
  22. static int banx_easy_chk(int ichi);
  23. static int banx_easy_uchiage(int ichi);
  24. static int banx_dameadd(GCELL *g_ptr, int ichi);
  25. static int banx_bancelldel(int ichi);
  26. static int banx_get_damenum(GCELL *g_ptr);
  27. static int banx_henkan(GCELL *gcellp, char henkan_territory_iro);
  28.  
  29. static int bansize, bansize2, up, down;
  30. static char ban[MAX_BANSIZE2];
  31. static char henkan_ban[MAX_BANSIZE2];
  32. static BANCELL  bancell[MAX_BANSIZE2];  /* 盤の上の一路一路 */
  33. static GCELL    init_gcell;
  34.  
  35. int banx_init()
  36. {
  37.     int i, j;
  38.     BAN_TYPE ban_type;
  39.     
  40.     Debugprint("igo:banx_init() start!\n");
  41.     ban_type = *title_bantype_read();
  42.     if( ban_type.type == NORMAL){
  43.         bansize = ban_type.size;
  44.         bansize2 = (bansize+1)*(bansize+2)+1;
  45.         up = -(bansize+1);
  46.         down = (bansize+1);
  47.     }
  48.     
  49.     ban_init(ban);
  50.     banx_do_judge(ban);
  51.     
  52.     return 0;
  53. }
  54.  
  55. int banx_end()
  56. {
  57.  
  58.         gcell_end();
  59.         damecell_end();
  60.  
  61.         return 0;
  62. }
  63.  
  64. int banx_handy_set( char current_ban[], int handy)
  65. {
  66.     
  67.     switch(handy){
  68.       case '2' + 0:
  69.         current_ban[96] = BLACK;
  70.         current_ban[324] = BLACK;
  71.         break;
  72.         
  73.       case '2' + 1:
  74.         current_ban[96] = BLACK;
  75.         current_ban[324] = BLACK;
  76.         current_ban[336] = BLACK;
  77.         break;
  78.         
  79.       case '2' + 2:
  80.         current_ban[84] = BLACK;
  81.         current_ban[96] = BLACK;
  82.         current_ban[324] = BLACK;
  83.         current_ban[336] = BLACK;
  84.         break;
  85.         
  86.       case '2' + 3:
  87.         current_ban[84] = BLACK;
  88.         current_ban[96] = BLACK;
  89.         current_ban[210] = BLACK;
  90.         current_ban[324] = BLACK;
  91.         current_ban[336] = BLACK;
  92.         break;
  93.         
  94.       case '2' + 4:
  95.         current_ban[84] = BLACK;
  96.         current_ban[96] = BLACK;
  97.         current_ban[204] = BLACK;
  98.         current_ban[216] = BLACK;
  99.         current_ban[324] = BLACK;
  100.         current_ban[336] = BLACK;
  101.         break;
  102.         
  103.       case '2' + 5:
  104.         current_ban[84] = BLACK;
  105.         current_ban[96] = BLACK;
  106.         current_ban[204] = BLACK;
  107.         current_ban[210] = BLACK;
  108.         current_ban[216] = BLACK;
  109.         current_ban[324] = BLACK;
  110.         current_ban[336] = BLACK;
  111.         break;
  112.         
  113.       case '2' + 6:
  114.         current_ban[84] = BLACK;
  115.         current_ban[90] = BLACK;
  116.         current_ban[96] = BLACK;
  117.         current_ban[204] = BLACK;
  118.         current_ban[216] = BLACK;
  119.         current_ban[324] = BLACK;
  120.         current_ban[330] = BLACK;
  121.         current_ban[336] = BLACK;
  122.         break;
  123.         
  124.       case '2' + 7:
  125.         current_ban[84] = BLACK;
  126.         current_ban[90] = BLACK;
  127.         current_ban[96] = BLACK;
  128.         current_ban[204] = BLACK;
  129.         current_ban[210] = BLACK;
  130.         current_ban[216] = BLACK;
  131.         current_ban[324] = BLACK;
  132.         current_ban[330] = BLACK;
  133.         current_ban[336] = BLACK;
  134.         break;
  135.         
  136.       case '2' + 8:
  137.         current_ban[84] = BLACK;
  138.         current_ban[96] = BLACK;
  139.         current_ban[324] = BLACK;
  140.         break;
  141.         
  142.       default:
  143.         break;
  144.     }
  145.     return 0;
  146. }
  147.  
  148. int banx_uchiage( char current_ban[], int ichi, int *uchiage_number)
  149. {
  150.     int i, j;
  151.     int houkou[4];
  152.     char input_color;
  153.     char rejudge_flg;
  154.     BANCELL *w_bancellp;
  155.     
  156.     *uchiage_number = 0;
  157.     /*  着手放棄の時 エラ-にする  */
  158.     if(ichi == 0){
  159.         return  -1;
  160.     }
  161.     
  162.     /*  入力画面がセ-ブしてある画面と同じか確認 */
  163.     input_color = current_ban[ichi];
  164.     current_ban[ichi] = BLANK;
  165.     
  166.     if(memcmp(ban, current_ban, sizeof(ban)) != 0){
  167.         memcpy(ban, current_ban, sizeof(ban));
  168.         banx_do_judge(ban);
  169.     }
  170.     ban[ichi] = input_color;
  171.     
  172.     /* 打ち上げるかどうかの判定 */
  173.     houkou[0] = up;
  174.     houkou[1] = LEFT;
  175.     houkou[2] = RIGHT;
  176.     houkou[3] = down;
  177.     
  178.     rejudge_flg = 0;
  179.     for(i=0;i<4;i++){
  180.         if(ban[ichi] != ban[ichi+houkou[i]] ){
  181.             if(ban[ichi+houkou[i]] != BLANK && ban[ichi+houkou[i]]!=WALL){
  182.                 if(banx_get_damenum(bancell[ichi+houkou[i]].g_ptr) == 1 ){
  183.                     rejudge_flg =1;
  184.                     j = 0;
  185.                     w_bancellp = bancell[ichi+houkou[i]].g_ptr->c_ptr;
  186.                     do{
  187.                         j++;
  188.                         ban[w_bancellp-bancell] = BLANK;
  189.                         w_bancellp=w_bancellp->next;
  190.                     }while(w_bancellp!=bancell[ichi+houkou[i]].g_ptr->c_ptr);
  191.                     *uchiage_number += j;
  192.                 }
  193.             }
  194.         }
  195.     }
  196.     
  197.     /* 再分析をするならば他の処理をする必要はない  */
  198.     if(rejudge_flg == 1){
  199.         banx_uchiage2(ichi);
  200.     }else{
  201.         if(banx_easy_chk(ichi) == 0){
  202.             banx_uchiage2(ichi);
  203.         }else{
  204.             banx_easy_uchiage(ichi);
  205.         }
  206.     }
  207.     
  208.     /*  画面の戻し処理 */
  209.     memcpy(current_ban, ban, sizeof(ban));
  210.     
  211.     return 0;
  212. }
  213.  
  214. /* グループのダメ(BLANKのみ)の数を数える */
  215. static int banx_get_damenum(GCELL *g_ptr)
  216. {
  217.     DAMECELL *w_damecellp;
  218.     int i;
  219.  
  220.     i=0;
  221.     w_damecellp = g_ptr->dame_ptr;
  222.     do{
  223.         if(bancell[w_damecellp->ichi].g_ptr->iro == BLANK){
  224.             i++;
  225.         }
  226.         w_damecellp = w_damecellp->next;
  227.     }while(w_damecellp != g_ptr->dame_ptr);
  228.            
  229.     return i;
  230. }
  231.  
  232. /* banx_uhciage2を使わずとも済む簡単な手かどうかの判断関数 */
  233. /* BLANKのグループが分割される可能性がなければ1を返す */
  234. static int banx_easy_chk(int ichi)
  235. {
  236.     int houkou[8];
  237.     char chk_area[8];
  238.     int i;
  239.     int brank_number, brank_number2;
  240.     
  241.     brank_number = brank_number2 = 0;
  242.     
  243.     houkou[0] = up+LEFT;
  244.     houkou[1] = up;
  245.     houkou[2] = up+RIGHT;
  246.     houkou[3] = RIGHT;
  247.     houkou[4] = down+RIGHT;
  248.     houkou[5] = down;
  249.     houkou[6] = down+LEFT;
  250.     houkou[7] = LEFT;    
  251.     
  252.     for(i=0;i<8;i++){
  253.         chk_area[i] = ban[ichi+houkou[i]];
  254.         if((i%2) == 1){
  255.             if(ban[ichi+houkou[i]] == BLANK){
  256.                 brank_number++;
  257.             }
  258.         }
  259.     }
  260.  
  261.     for(i=0;i<8;i++){
  262.         if((i%2) == 1){
  263.             if(ban[ichi+houkou[i]] != BLANK){
  264.                 chk_area[i-1] = chk_area[i] = chk_area[(i+1)%8] = WALL;
  265.             }
  266.         }
  267.     }
  268.  
  269.     for(i=0;i<8;i++){
  270.         if(chk_area[i] == BLANK){
  271.             brank_number2++;
  272.         }
  273.     }
  274.  
  275.     if(brank_number == 0){
  276.         return 0;
  277.     }
  278.  
  279.     if((brank_number*2-1) == brank_number2){
  280.         return 1;
  281.     }
  282.     
  283.     return 0;
  284. }
  285.  
  286. /* banx_uhciage2を使わずとも済む簡単な手の入力関数 */
  287. /* 対応しているのはBLANKのグループが分割されない場合 */
  288. static int banx_easy_uchiage(int ichi)
  289. {
  290.     int i;
  291.     int houkou[4];
  292.  
  293.     houkou[0] = up;
  294.     houkou[1] = LEFT;
  295.     houkou[2] = RIGHT;
  296.     houkou[3] = down;
  297.  
  298.     /* 隣接する石の同色のグループの削除 */
  299.     for(i=0;i<4;i++){
  300.         if(ban[ichi] == ban[ichi+houkou[i]] && bancell[ichi+houkou[i]].g_ptr != NULL){
  301.             banx_gdel(bancell[ichi+houkou[i]].g_ptr);
  302.         }
  303.     }
  304.     
  305.     /* ダメの追加 */
  306.     banx_dameadd(bancell[ichi].g_ptr, ichi);
  307.  
  308.     /* territoryの削除 */
  309.     banx_bancelldel(ichi);
  310.  
  311.     /* グループの作成 */
  312.     bancell[ichi].g_ptr = NULL;
  313.     banx_ginit(ichi);    
  314.  
  315.     return 0;
  316. }
  317.  
  318. /* ダメのグループへの追加 */
  319. static int banx_dameadd(GCELL *g_ptr, int ichi)
  320. {
  321.     DAMECELL *w_damep;
  322.     
  323.     /* dame_ptr はNULL が設置してある */
  324.     if(g_ptr->dame_ptr==NULL){
  325.         w_damep = damecell_get();
  326.         g_ptr->dame_ptr = w_damep;
  327.         w_damep->next = w_damep;
  328.         w_damep->ichi = ichi;
  329.     }else{
  330.         w_damep = damecell_get();
  331.         w_damep->next = g_ptr->dame_ptr->next;
  332.         g_ptr->dame_ptr->next = w_damep;
  333.         w_damep->ichi = ichi;
  334.     }
  335.     /* ダメ数の計算 */
  336.     g_ptr->dame_number++;
  337.     /* territoty_iro の決定 */
  338.     if(g_ptr->territory_iro != BLANK){
  339.         if(g_ptr->territory_iro == WALL){
  340.             g_ptr->territory_iro = ban[ichi];
  341.         }else{
  342.             if(g_ptr->territory_iro != ban[ichi]){
  343.                 g_ptr->territory_iro = BLANK;
  344.             }
  345.         }
  346.     }
  347.     
  348.     return 0;
  349. }
  350.  
  351. /* bancellのグループからの削除 */
  352. static int banx_bancelldel(int ichi)
  353. {
  354.     BANCELL *w_bancellp;
  355.  
  356.     w_bancellp = bancell[ichi].g_ptr->c_ptr;
  357.     if(w_bancellp == w_bancellp->next){
  358.         printf("banx_bancelldel abnormal end !\n");
  359.     }
  360.  
  361.     while(w_bancellp->next != &bancell[ichi]){
  362.         w_bancellp = w_bancellp->next;
  363.     }
  364.     w_bancellp->next = bancell[ichi].next;
  365.  
  366.     /* 削除したbancellがグループの直下の場合c_ptrを変更する */
  367.     if(bancell[ichi].g_ptr->c_ptr == &bancell[ichi]){
  368.         bancell[ichi].g_ptr->c_ptr = w_bancellp->next;
  369.     }
  370.            
  371.     return 0;
  372. }
  373.  
  374. /* banx_uhciage の下請け関数 */
  375. static int banx_uchiage2(int ichi)
  376. {
  377.     int houkou[5];
  378.     int i;
  379.     
  380.     houkou[0] = up;
  381.     houkou[1] = LEFT;
  382.     houkou[2] = RIGHT;
  383.     houkou[3] = down;
  384.     houkou[4] = 0;
  385.     
  386.     for(i=0;i<5;i++){
  387.         if(ban[ichi+houkou[i]] != WALL){
  388.             if(bancell[ichi+houkou[i]].g_ptr != NULL){
  389.                 banx_gdel(bancell[ichi+houkou[i]].g_ptr);
  390.             }
  391.         }
  392.     }
  393.  
  394.     for(i=0;i<5;i++){
  395.         if(ban[ichi+houkou[i]] != WALL){
  396.             banx_ginit(ichi+houkou[i]);    
  397.         }
  398.     }
  399.  
  400.     return 0;
  401. }
  402.  
  403. /* グループを削除する関数 */
  404. static int banx_gdel(GCELL *g_ptr)
  405. {
  406.     DAMECELL *w_damep, *save_damep;
  407.     GCELL *w_g_ptr;
  408.     BANCELL *w_bancellp;
  409.  
  410.     /* 絶対満たす条件のはずだが一応確認 */
  411.     if(g_ptr == NULL){
  412.         printf("g_ptr abnormal!\n");
  413.     }
  414.  
  415.     /* 一番最初の画面ではg_ptr->dame_ptr は NULL */
  416.     if( g_ptr->dame_ptr != NULL){
  417.         /* dame_ptrの解放 */
  418.         w_damep = g_ptr->dame_ptr;
  419.         do{
  420.             save_damep = w_damep->next;
  421.             damecell_free(w_damep);
  422.             w_damep = save_damep;
  423.         }while(w_damep != g_ptr->dame_ptr);
  424.     }
  425.     
  426.     if(g_ptr->c_ptr != NULL){
  427.         /* dame_ptrの解放 */
  428.         w_bancellp = g_ptr->c_ptr;
  429.         do{
  430.             w_bancellp->g_ptr = NULL;
  431.             w_bancellp = w_bancellp->next;
  432.         }while(w_bancellp != g_ptr->c_ptr);
  433.     }
  434.     
  435.     /* g_ptr の解放 */
  436.     for(w_g_ptr = &init_gcell;w_g_ptr->next != g_ptr;w_g_ptr=w_g_ptr->next){
  437.         ;
  438.     }
  439.     w_g_ptr->next = g_ptr->next;
  440.     gcell_free(g_ptr);
  441.  
  442.     return 0;
  443. }
  444.  
  445. /* グループを設定する際の初期化 banx_uchiage2 と banx_gchk で使用 */
  446. static int banx_ginit(int ichi)
  447. {
  448.     char dameban[MAX_BANSIZE2];
  449.     
  450.     if(bancell[ichi].g_ptr == NULL){
  451.         bancell[ichi].g_ptr = gcell_get();
  452.         bancell[ichi].g_ptr->next = init_gcell.next;
  453.         init_gcell.next = bancell[ichi].g_ptr;
  454.         
  455.         bancell[ichi].g_ptr->iro = ban[ichi];
  456.         bancell[ichi].g_ptr->c_ptr = &bancell[ichi];
  457.         bancell[ichi].next = &bancell[ichi];
  458.         bancell[ichi].g_ptr->dame_ptr = NULL;
  459.         bancell[ichi].g_ptr->dame_number = 0;
  460.         /* territory_iroのクリアの意味でWALLを設定 */
  461.         /* BLANK以外のエリアは特に何の色を設定しても問題ない ? */
  462.         bancell[ichi].g_ptr->territory_iro=WALL;
  463.         bancell[ichi].g_ptr->territory_number = 1;
  464.         
  465.         memset(dameban, 0, sizeof(dameban)); 
  466.         banx_gset(bancell[ichi].g_ptr, ichi, dameban);
  467.     }
  468.     
  469.     return 0;
  470. }
  471.  
  472. /* 個々の石ダメごとにグループを設定 再帰関数 */
  473. static int banx_gset(GCELL *g_ptr, int ichi, char *dameban)
  474. {
  475.     int houkou[4];
  476.     int i;
  477.     
  478.     houkou[0] = up;
  479.     houkou[1] = LEFT;
  480.     houkou[2] = RIGHT;
  481.     houkou[3] = down;
  482.     
  483.     for(i=0;i<4;i++){
  484.         /* 個々の石をグループに設定  */
  485.         if(ban[ichi+houkou[i]] == ban[ichi]){
  486.             if(bancell[ichi+houkou[i]].g_ptr != g_ptr){
  487.                 bancell[ichi+houkou[i]].g_ptr = g_ptr;
  488.                 bancell[ichi+houkou[i]].next = bancell[ichi].next;
  489.                 bancell[ichi].next = &bancell[ichi+houkou[i]];
  490.                 g_ptr->territory_number++;
  491.                 banx_gset(g_ptr, ichi+houkou[i], dameban);
  492.             }
  493.         }else{
  494.             /* グループごとのダメの設定 */
  495.             if(ban[ichi+houkou[i]]!=WALL && dameban[ichi+houkou[i]] != 1){
  496.                 dameban[ichi+houkou[i]] = 1;
  497.                 banx_dameadd(g_ptr, ichi+houkou[i]);
  498.             }
  499.         }
  500.     }
  501.     return 0;
  502. }    
  503.  
  504. int banx_judge(char current_ban[])
  505. {
  506.     int i;
  507.     
  508.     /*  入力画面がセ-ブしてある画面と同じか確認 */
  509.     for(i=0;i<MAX_BANSIZE2;i++){
  510.         ban[i] = current_ban[i];
  511.     }
  512.     
  513.     banx_do_judge(ban);
  514.     
  515.     /*  形勢判断の時は表示する画面を設定 */
  516.     for(i=0;i<MAX_BANSIZE2;i++){
  517.         henkan_ban[i] = ban[i];
  518.     }
  519.     
  520.     return 0;
  521. }
  522.  
  523. static int banx_do_judge(char current_ban[])
  524. {
  525.     int i;
  526.     
  527.     for(i=0;i<bansize2;i++){
  528.         bancell[i].g_ptr = NULL;
  529.         bancell[i].next = NULL;
  530.     }
  531.     gcell_init();
  532.     damecell_init();
  533.     init_gcell.next = &init_gcell;
  534.     
  535.     banx_gchk();
  536.     
  537.     return 0;
  538. }
  539.  
  540. /* グル-プを設定してバンセルを位置づける */
  541. static int banx_gchk()
  542. {
  543.     int i, j;
  544.     int ichi;
  545.    
  546.     /* グル-プの判別 */
  547.     for(i=1;i<bansize+1;i++){
  548.         for(j=1;j<bansize+1;j++){
  549.             ichi = i*(bansize+1) + j;
  550.             banx_ginit(ichi);    
  551.         }
  552.     }
  553.     
  554.     return 0;
  555. }
  556.  
  557. /*  盤面にデ-タを表示する */
  558. char *banx_judgedisp()
  559. {
  560.     BANCELL *w_ptr;
  561.     GCELL       *cur_g_ptr;
  562.     
  563.     for(cur_g_ptr=init_gcell.next;cur_g_ptr!=&init_gcell;
  564.         cur_g_ptr=cur_g_ptr->next){
  565.         switch (cur_g_ptr->iro){
  566.           case BLACK:   
  567.           case WHITE:
  568.             w_ptr=cur_g_ptr->c_ptr;
  569.             do{
  570.                 if(cur_g_ptr->henkan_territory_iro==BLANK){
  571.                     henkan_ban[w_ptr-bancell] = cur_g_ptr->iro;
  572.                 }else{
  573.                     if(cur_g_ptr->iro == BLACK){
  574.                         henkan_ban[w_ptr-bancell]=BLACK_CAPTURE;
  575.                     }else{
  576.                         henkan_ban[w_ptr-bancell]=WHITE_CAPTURE;
  577.                     }
  578.                 }
  579.                 w_ptr=w_ptr->next;
  580.             }while(w_ptr!=cur_g_ptr->c_ptr);
  581.             break;
  582.           case BLANK:
  583.             w_ptr=cur_g_ptr->c_ptr;
  584.             do{
  585.                 if(henkan_ban[w_ptr-bancell]!=WALL_TERRITORY){
  586.                     if(cur_g_ptr->henkan_territory_iro==BLANK){
  587.                         if(cur_g_ptr->territory_iro==BLACK)
  588.                             henkan_ban[w_ptr-bancell]=BLACK_TERRITORY;
  589.                         else if(cur_g_ptr->territory_iro==WHITE){
  590.                             henkan_ban[w_ptr-bancell]=WHITE_TERRITORY;
  591.                         }else{
  592.                             henkan_ban[w_ptr-bancell]=BLANK;
  593.                         }
  594.                     }else{
  595.                         if(cur_g_ptr->henkan_territory_iro==BLACK)
  596.                             henkan_ban[w_ptr-bancell]=BLACK_TERRITORY;
  597.                         else if(cur_g_ptr->henkan_territory_iro==WHITE){
  598.                             henkan_ban[w_ptr-bancell]=WHITE_TERRITORY;
  599.                         }else{
  600.                             henkan_ban[w_ptr-bancell]=BLANK;
  601.                         }
  602.                     }
  603.                 }
  604.                 w_ptr=w_ptr->next;
  605.             }while(w_ptr!=cur_g_ptr->c_ptr);
  606.             break;
  607.           default: break;
  608.         }
  609.     }
  610.  
  611. #if DEBUG
  612.     int i;
  613.     char iro_str[16];
  614.     char debug_str[100];
  615.  
  616.     for(i=0;i<MAX_BANSIZE2;i++){
  617.         switch (henkan_ban[i]){
  618.         case BLANK: strcpy(iro_str, "BLANK"); break;
  619.         case WHITE: strcpy(iro_str, "WHITE"); break;
  620.         case BLACK: strcpy(iro_str, "BLACK"); break;
  621.         case WHITE_TERRITORY: strcpy(iro_str, "WHITE_TERRITORY"); break;
  622.         case BLACK_TERRITORY: strcpy(iro_str, "BLACK_TERRITORY"); break;
  623.         case WHITE_CAPTURE: strcpy(iro_str, "WHITE_CAPTURE"); break;
  624.         case BLACK_CAPTURE: strcpy(iro_str, "BLACK_CAPTURE"); break;
  625.         default: break;
  626.         }
  627.         sprintf(debug_str, "henkan_ban[%d] = %s\n", i, iro_str);
  628.         debugprint(debug_str);
  629.     }
  630. #endif
  631.  
  632.     return henkan_ban;
  633. }
  634.  
  635. /*  地の数デ-タを表示する */
  636. int banx_territory(int *black_t_number, int *white_t_number)
  637. {
  638.     GCELL       *current_g_ptr;
  639.     
  640.     *black_t_number=0;
  641.     *white_t_number=0;
  642.     for(current_g_ptr=init_gcell.next;current_g_ptr!=&init_gcell;
  643.         current_g_ptr=current_g_ptr->next){
  644.         if(current_g_ptr->henkan_territory_iro==BLANK){
  645.             switch (current_g_ptr->territory_iro){
  646.               case BLACK:
  647.                   *black_t_number+=current_g_ptr->territory_number;
  648.                   break;
  649.               case WHITE:
  650.                   *white_t_number+=current_g_ptr->territory_number;
  651.                   break;
  652.               default: break;
  653.             }
  654.         }else{
  655.             switch (current_g_ptr->iro){
  656.               case BLACK:
  657.                   *white_t_number+=current_g_ptr->territory_number*2;
  658.                   break;
  659.               case WHITE:
  660.                   *black_t_number+=current_g_ptr->territory_number*2;
  661.                   break;
  662.               case BLANK:
  663.                   if(current_g_ptr->henkan_territory_iro==BLACK){
  664.                       *black_t_number+=current_g_ptr->territory_number;
  665.                   }else{
  666.                       *white_t_number+=current_g_ptr->territory_number;
  667.                   }
  668.                   break;
  669.               default: break;
  670.             }
  671.         }
  672.     }
  673.     
  674.     return 0;
  675.     
  676. }
  677.  
  678. /*  形勢判断を行っている時の盤の操作を行う */
  679. int banx_put( int ichi)
  680. {
  681.     DAMECELL *w_ptr;
  682.     char henkan_territory_iro; /* 変換後の領地の所有者 */
  683.     
  684.     if(ban[ichi]==BLANK){
  685.         if(henkan_ban[ichi]==WALL_TERRITORY){
  686.             henkan_ban[ichi]=BLANK;
  687.             ++(bancell[ichi].g_ptr->territory_number);
  688.         }else{
  689.             henkan_ban[ichi]=WALL_TERRITORY;
  690.             --(bancell[ichi].g_ptr->territory_number);
  691.         }
  692.     }else{
  693.         if(bancell[ichi].g_ptr->henkan_territory_iro==BLANK){
  694.             henkan_territory_iro=1-bancell[ichi].g_ptr->iro;
  695.         }else{
  696.             henkan_territory_iro=BLANK;
  697.         }
  698.         bancell[ichi].g_ptr->henkan_territory_iro=henkan_territory_iro;
  699.         if((w_ptr=bancell[ichi].g_ptr->dame_ptr)!=NULL){
  700.             do{
  701.                 banx_henkan(bancell[w_ptr->ichi].g_ptr, henkan_territory_iro);
  702.                 w_ptr=w_ptr->next;
  703.             }while(w_ptr!=bancell[ichi].g_ptr->dame_ptr);
  704.         }
  705.     }
  706.     
  707.     return 0;
  708.     
  709. }
  710.  
  711. /* 指定されたグル-プと隣接したグル-プの取られ石かそうでないかの変換  */
  712. static int banx_henkan(GCELL *gcellp, char henkan_territory_iro)
  713. {
  714.     DAMECELL *w_ptr;
  715.     
  716.     if(henkan_territory_iro==BLANK){
  717.         if(gcellp->henkan_territory_iro==BLANK){
  718.             return 0;
  719.         }
  720.         gcellp->henkan_territory_iro=henkan_territory_iro;
  721.     }else{
  722.         if(gcellp->iro==henkan_territory_iro
  723.            || gcellp->henkan_territory_iro==henkan_territory_iro){
  724.             return 0;
  725.         }
  726.         gcellp->henkan_territory_iro=henkan_territory_iro;
  727.         
  728.     }
  729.     
  730.     if((w_ptr=gcellp->dame_ptr)!=NULL){
  731.         do{
  732.             banx_henkan(bancell[w_ptr->ichi].g_ptr, henkan_territory_iro);
  733.             w_ptr=w_ptr->next;
  734.         }while(w_ptr!=gcellp->dame_ptr);
  735.     }
  736.     return 0;
  737. }
  738.  
  739. int banx_debugprint()
  740. {
  741.     static int i = 0;
  742.     FILE *fp;
  743.     GCELL       *cur_g_ptr;
  744.     BANCELL *w_ptr;
  745.     DAMECELL *w_damep;
  746.     
  747.     if(++i < 67){
  748.         return -1;
  749.     }
  750.     
  751.     if((fp=fopen("debug.txt","a"))==NULL){
  752.         printf("debug txt open error!\n");
  753.         return -1;
  754.     }
  755.     
  756.     fprintf(fp, "banx_debugprint(%d)!\n", i);
  757.     for(cur_g_ptr=init_gcell.next;cur_g_ptr!=&init_gcell;
  758.         cur_g_ptr=cur_g_ptr->next){
  759.         fprintf(fp, "g_ptr = %d\n", cur_g_ptr);
  760.         fprintf(fp, "g_ptr.iro = %d\n", cur_g_ptr->iro);
  761.         fprintf(fp, "g_ptr.territory_number = %d\n", cur_g_ptr->territory_number);
  762.         /*
  763.           if(cur_g_ptr->iro != BLANK){
  764.           */
  765.         w_ptr=cur_g_ptr->c_ptr;
  766.         do{
  767.             fprintf(fp, " bancell ichi = (%d, %d)\n", (w_ptr - bancell)%(bansize+1), (w_ptr -bancell)/(bansize+1));
  768.             w_ptr=w_ptr->next;
  769.         }while(w_ptr!=cur_g_ptr->c_ptr);
  770.         /*
  771.           }
  772.           */
  773.         fprintf(fp, "g_ptr.dame_number = %d\n", cur_g_ptr->dame_number);
  774.         if(cur_g_ptr->dame_ptr==NULL){
  775.             ;
  776.         }else{
  777.             w_damep=cur_g_ptr->dame_ptr;
  778.             do{
  779.                 fprintf(fp, " damecell ichi = (%d, %d)\n", (w_damep->ichi)%(bansize+1), (w_damep->ichi)/(bansize+1));
  780.                 w_damep=w_damep->next;
  781.             }while(w_damep!=cur_g_ptr->dame_ptr);
  782.         }
  783.         
  784.         fprintf(fp, "g_ptr.territory_iro = %d\n", cur_g_ptr->territory_iro);
  785.         fprintf(fp, "g_ptr.henkan_territory_iro = %d\n\n", cur_g_ptr->henkan_territory_iro);
  786.     }
  787.     
  788.     fprintf(fp, "banx_debugprint end! \n\n");
  789.     
  790.     fclose(fp);
  791.     
  792.     return 0;
  793. }
  794.  
  795.